<?php
/**
 * Author: 式神(vashi)
 * email: 289650682@qq.com
 * Date: 2019/1/30 18:25
 * FileName: Common.php
 */

namespace app\common\controller;


use think\App;
use think\Controller;
use think\db\Where;

class Common extends Controller
{
    protected $res;
    protected $db;
    public function __construct(App $app = null)
    {
        parent::__construct($app);
        $this->res=[
            'code'=>1,
            'msg'=>"请求出错"
        ];
    }

    protected function getMap($data=[]){
        $where=[];
        foreach($data as $k =>$v){
            if(preg_match('/like__(.*)/',$k,$match)){
                if($v && $v!=""){
                    $where[$match[1]]=['like','%'.$v.'%'];
                }
            }
            if(preg_match('/eq__(.*)/',$k,$match)){
                if($v){
                    $where[$match[1]]=$v;
                }
            }
        }
        return new Where($where);
    }

    protected function getOrder($data=[]){
        if(isset($data['field'])){
            $field=$data['field'];
            $order=$data['order'];
            $orders=$field." ".$order;
        }else{
            $orders="id asc";
        }
        return $orders;
    }
}